home *** CD-ROM | disk | FTP | other *** search
/ Digitalfoto 118 / Digitalfoto 118.iso / mac / programas / 00 / start.swf / scripts / __Packages / v2bScroller.as
Text File  |  2009-11-16  |  11KB  |  364 lines

  1. class v2bScroller extends mx.core.UIComponent
  2. {
  3.    var mouseMoveListener = new Object();
  4.    var scroll_direction = "vertical";
  5.    var snap_offset = 0;
  6.    var scroll_percentage = 0;
  7.    var use_invisible_mask = false;
  8.    var auto_read_target_size = true;
  9.    var _enabled = false;
  10.    var read_target_size_interval = 60;
  11.    var target_start_x = 0;
  12.    var target_start_y = 0;
  13.    var target_height = 0;
  14.    var target_width = 0;
  15.    var scroller_height = 0;
  16.    var scroller_width = 0;
  17.    function v2bScroller()
  18.    {
  19.       super();
  20.       this.onUnload = function()
  21.       {
  22.          if(this.oSipDWs != undefined)
  23.          {
  24.             this.oSipDWs.removeMovieClip();
  25.             this.oSipDWs = undefined;
  26.          }
  27.       };
  28.    }
  29.    function set autoReadTargetSize(val)
  30.    {
  31.       this.auto_read_target_size = val;
  32.       this.invalidate();
  33.    }
  34.    function get autoReadTargetSize()
  35.    {
  36.       return this.auto_read_target_size;
  37.    }
  38.    function set useInvisibleMask(val)
  39.    {
  40.       this.use_invisible_mask = val;
  41.       this.invalidate();
  42.    }
  43.    function get useInvisibleMask()
  44.    {
  45.       return this.use_invisible_mask;
  46.    }
  47.    function set enabled(val)
  48.    {
  49.    }
  50.    function get enabled()
  51.    {
  52.       return this._enabled;
  53.    }
  54.    function set snapOffset(val)
  55.    {
  56.       this.snap_offset = val;
  57.       this.invalidate();
  58.    }
  59.    function get snapOffset()
  60.    {
  61.       return this.snap_offset;
  62.    }
  63.    function set scrollDirection(val)
  64.    {
  65.       this.scroll_direction = val;
  66.       this.invalidate();
  67.    }
  68.    function get scrollDirection()
  69.    {
  70.       return this.scroll_direction;
  71.    }
  72.    function set viewAreaWidth(val)
  73.    {
  74.       this.view_area_width = val;
  75.       this.invalidate();
  76.    }
  77.    function get viewAreaWidth()
  78.    {
  79.       return this.view_area_width;
  80.    }
  81.    function set viewAreaHeight(val)
  82.    {
  83.       this.view_area_height = val;
  84.       this.invalidate();
  85.    }
  86.    function get viewAreaHeight()
  87.    {
  88.       return this.view_area_height;
  89.    }
  90.    function set targetMovieClip(val)
  91.    {
  92.       var _loc3_ = String(this.target_mc);
  93.       if(typeof val == "string")
  94.       {
  95.          this.target_mc = this._parent[val];
  96.       }
  97.       else
  98.       {
  99.          this.target_mc = val;
  100.       }
  101.       if(this.oSipDWs != undefined)
  102.       {
  103.          this.oSipDWs.removeMovieClip();
  104.          this.oSipDWs = undefined;
  105.       }
  106.       this.target_start_x = Math.round(this.target_mc._x);
  107.       this.target_start_y = Math.round(this.target_mc._y);
  108.       this.target_mc._x = this.target_start_x;
  109.       this.target_mc._y = this.target_start_y;
  110.       this.invalidate();
  111.    }
  112.    function get targetMovieClip()
  113.    {
  114.       return this.target_mc;
  115.    }
  116.    function set scrollPercentage(val)
  117.    {
  118.       if(val < 0)
  119.       {
  120.          val = 0;
  121.       }
  122.       else if(val > 100)
  123.       {
  124.          val = 100;
  125.       }
  126.       this.scroll_percentage = val;
  127.       this.invalidate();
  128.    }
  129.    function get scrollPercentage()
  130.    {
  131.       return this.scroll_percentage;
  132.    }
  133.    function set targetHeight(val)
  134.    {
  135.       this.target_height = val;
  136.       this.invalidate();
  137.    }
  138.    function get targetHeight()
  139.    {
  140.       return this.target_height;
  141.    }
  142.    function set targetWidth(val)
  143.    {
  144.       this.target_width = val;
  145.       this.invalidate();
  146.    }
  147.    function get targetWidth()
  148.    {
  149.       return this.target_width;
  150.    }
  151.    function setSize(s_width, s_height)
  152.    {
  153.       if(s_width != null && s_width != undefined)
  154.       {
  155.          this.scroller_width = s_width;
  156.          this.__width = this.scroller_width;
  157.       }
  158.       if(s_height != null && s_height != undefined)
  159.       {
  160.          this.scroller_height = s_height;
  161.          this.__height = this.scroller_height;
  162.       }
  163.       this.invalidate();
  164.    }
  165.    function init()
  166.    {
  167.       super.init();
  168.    }
  169.    function createChildren()
  170.    {
  171.       var _loc2_ = this;
  172.       this.slider_mc.onPress = this.slider_onPress;
  173.       this.slider_mc.onRelease = this.slider_mc.onReleaseOutside = this.slider_onRelease;
  174.       this.slider_mc.onRollOver = this.slider_onRollOver;
  175.       this.slider_mc.onRollOut = this.slider_onRollOut;
  176.       this.size();
  177.    }
  178.    function draw()
  179.    {
  180.       super.draw();
  181.    }
  182.    function size()
  183.    {
  184.       super.size();
  185.       if(this.scroll_direction == "vertical")
  186.       {
  187.          this.slider_mc._rotation = 0;
  188.          this.slider_mc._y = 0;
  189.          this.track_state_mc._rotation = 0;
  190.          this.track_state_mc._y = 0;
  191.       }
  192.       else
  193.       {
  194.          this.slider_mc._rotation = -90;
  195.          this.slider_mc._y = this.slider_mc._height;
  196.          this.track_state_mc._rotation = -90;
  197.          this.track_state_mc._y = this.track_state_mc._height;
  198.       }
  199.       this.invalidate();
  200.    }
  201.    function invalidate()
  202.    {
  203.       super.invalidate();
  204.       var _loc3_ = this;
  205.       this.scroller_width = Math.round(this.__width);
  206.       this.scroller_height = Math.round(this.__height);
  207.       if(this.target_mc == undefined || this.target_mc._x == undefined || this.view_area_height == undefined || this.view_area_width == undefined)
  208.       {
  209.          if(this.oSipDWs != undefined)
  210.          {
  211.             this.oSipDWs.removeMovieClip();
  212.             this.oSipDWs = undefined;
  213.          }
  214.          this._visible = false;
  215.          this._enabled = false;
  216.          return undefined;
  217.       }
  218.       if(!this.use_invisible_mask)
  219.       {
  220.          if(this.oSipDWs == undefined)
  221.          {
  222.             this.addMask();
  223.             this.target_mc.setMask(this.oSipDWs);
  224.          }
  225.       }
  226.       else if(this.oSipDWs != undefined)
  227.       {
  228.          this.oSipDWs.removeMovieClip();
  229.          this.oSipDWs = undefined;
  230.       }
  231.       this.update();
  232.       if(this.auto_read_target_size)
  233.       {
  234.          this.read_target_size_delay = setInterval(_loc3_,"getTargetSize",this.read_target_size_interval);
  235.       }
  236.       else
  237.       {
  238.          clearInterval(this.read_target_size_delay);
  239.       }
  240.    }
  241.    function addMask()
  242.    {
  243.       var _loc2_ = "mask_" + Math.round(Math.random() * 10000000);
  244.       while(this._parent[_loc2_] != undefined)
  245.       {
  246.          _loc2_ = "mask_" + Math.round(Math.random() * 10000000);
  247.       }
  248.       this.oSipDWs = this.target_mc._parent.createEmptyMovieClip(_loc2_,this.target_mc._parent.getNextHighestDepth());
  249.       this.oSipDWs.beginFill(0);
  250.       this.oSipDWs.moveTo(0,0);
  251.       this.oSipDWs.lineTo(0,100);
  252.       this.oSipDWs.lineTo(100,100);
  253.       this.oSipDWs.lineTo(100,0);
  254.       this.oSipDWs.endFill();
  255.       this.oSipDWs._x = this.target_start_x;
  256.       this.oSipDWs._y = this.target_start_y;
  257.    }
  258.    function setMaskSize()
  259.    {
  260.       this.oSipDWs._width = this.view_area_width;
  261.       this.oSipDWs._height = this.view_area_height;
  262.    }
  263.    function update()
  264.    {
  265.       if(this.auto_read_target_size)
  266.       {
  267.          this.target_height = Math.ceil(this.target_mc._height);
  268.          this.target_width = Math.ceil(this.target_mc._width);
  269.       }
  270.       if(!this.use_invisible_mask)
  271.       {
  272.          this.setMaskSize();
  273.       }
  274.       if(this.scroll_direction == "vertical")
  275.       {
  276.          if(this.target_height + this.snap_offset < this.view_area_height)
  277.          {
  278.             this._visible = false;
  279.             this._enabled = false;
  280.             this.scroll_percentage = 0;
  281.          }
  282.          else
  283.          {
  284.             this._visible = true;
  285.             this._enabled = true;
  286.          }
  287.       }
  288.       else if(this.target_width + this.snap_offset < this.view_area_width)
  289.       {
  290.          this._visible = false;
  291.          this._enabled = false;
  292.          this.scroll_percentage = 0;
  293.       }
  294.       else
  295.       {
  296.          this._visible = true;
  297.          this._enabled = true;
  298.       }
  299.       if(this.scroll_direction == "vertical")
  300.       {
  301.          this.track_state_mc._height = this.scroller_height;
  302.          this.slider_mc._y = Math.round((this.scroller_height - this.slider_mc._height) * this.scroll_percentage / 100);
  303.          this.target_mc._y = Math.round(this.target_start_y - (this.target_height + this.snap_offset - this.view_area_height) * this.scroll_percentage / 100);
  304.       }
  305.       else
  306.       {
  307.          this.track_state_mc._rotation = 0;
  308.          this.track_state_mc._height = this.scroller_width;
  309.          this.track_state_mc._rotation = -90;
  310.          this.slider_mc._x = Math.round((this.scroller_width - this.slider_mc._width) * this.scroll_percentage / 100);
  311.          this.target_mc._x = Math.round(this.target_start_x - (this.target_width + this.snap_offset - this.view_area_width) * this.scroll_percentage / 100);
  312.       }
  313.    }
  314.    function slider_onPress()
  315.    {
  316.       this.gotoAndStop("pressed");
  317.       if(this._parent.scroll_direction == "vertical")
  318.       {
  319.          this.startDrag(false,0,0,0,this._parent.scroller_height - this._height);
  320.       }
  321.       else
  322.       {
  323.          this.startDrag(false,0,this._height,this._parent.scroller_width - this._width,this._height);
  324.       }
  325.       this.onMouseMove = function()
  326.       {
  327.          if(this._parent.scroll_direction == "vertical")
  328.          {
  329.             this._parent.scroll_percentage = this._parent.slider_mc._y * 100 / (this._parent.scroller_height - this._parent.slider_mc._height);
  330.             this._parent.target_mc._y = Math.round(this._parent.target_start_y - (this._parent.target_height + this._parent.snap_offset - this._parent.view_area_height) * this._parent.scroll_percentage / 100);
  331.          }
  332.          else
  333.          {
  334.             this._parent.scroll_percentage = this._parent.slider_mc._x * 100 / (this._parent.scroller_width - this._parent.slider_mc._width);
  335.             this._parent.target_mc._x = Math.round(this._parent.target_start_x - (this._parent.target_width + this._parent.snap_offset - this._parent.view_area_width) * this._parent.scroll_percentage / 100);
  336.          }
  337.       };
  338.    }
  339.    function slider_onRelease()
  340.    {
  341.       this.gotoAndStop("normal");
  342.       this.stopDrag();
  343.       this.onMouseMove();
  344.       delete this.onMouseMove;
  345.    }
  346.    function slider_onRollOver()
  347.    {
  348.       this.gotoAndStop("over");
  349.    }
  350.    function slider_onRollOut()
  351.    {
  352.       this.gotoAndStop("normal");
  353.    }
  354.    function getTargetSize()
  355.    {
  356.       if(this.target_height != Math.ceil(this.target_mc._height) || this.target_width != Math.ceil(this.target_mc._width))
  357.       {
  358.          this.target_height = Math.ceil(this.target_mc._height);
  359.          this.target_width = Math.ceil(this.target_mc._width);
  360.          this.update();
  361.       }
  362.    }
  363. }
  364.